package com.ia.aistream.manager.operating.util;

import com.aspose.diagram.Diagram;
import com.aspose.diagram.SaveFileFormat;
import com.ia.aistream.common.utils.StringUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class OtherTest {
    public static void main(String[] args) throws Exception {
//        String content = "附录1：系统主要参数表（1/2）";
//        String listText = "";
//        System.out.println(isTitle(content, listText));
//
//        String img = "41.2.3";
//        int index = img.indexOf(".");
//        System.out.println(index);

        String dataDir = "D:\\a\\";
        Diagram diagram = new Diagram(dataDir + "jk.vsd");
//        diagram.save("D:/a/ffk.pdf", SaveFileFormat.PDF);
//        diagram.setVersion("11");
        diagram.save("D:/a/ffk.vsdx", SaveFileFormat.VSDX);
    }

    /** 判断是否为标题  **/
    public static int isTitle(String content, String listText){

        String trim = listText + "  " + content;
        trim = trim.replace("．", ".").trim();
        if(StringUtils.isEmpty(trim)){
            return 0;
        }

        return getNum(trim);
    }

    /***
     * 内容
     * @param msg
     * @return
     */
    public static int getNum(String msg){
        String sum = "";
        if(!msg.contains(".") && !msg.contains(" ")){
            return 0;
        }
        for (int i=0; i<msg.length(); i++){
            if(msg.charAt(i)>='0' && msg.charAt(i)<='9'){
                sum += msg.charAt(i);
            }else if(msg.charAt(i)=='.'){
                sum += msg.charAt(i);
            }else{
                break;
            }
        }
        if(msg.startsWith("附录")){
            return 2;
        }
        if(StringUtils.isEmpty(sum)){
            return 0;
        }
        String[] split = sum.split("\\.");
        if(split.length>2){
            return 0;
        }
        if (!sum.contains(".")){
            return 1;
        }
        if(sum.lastIndexOf(".")==sum.length()-1){
            return 1;
        }
        if(sum.lastIndexOf(".")<sum.length()-1 && sum.lastIndexOf(".")>0){
            return 2;
        }
        return 0;
    }

    /***
     * 判断是否为一级标题
     * @param msg
     * @return
     */
    private static boolean isOnlyNum(String msg){
        String vPattern ="^\\d{1,2}\\.?$";
        Pattern vR = Pattern.compile(vPattern);
        Matcher vM = vR.matcher(msg);
        return vM.matches();
    }

    private static boolean isStartNum(String msg){
        String vPattern ="^\\d{1,2}\\.\\d*\\s{0,2}.*$";
        Pattern vR = Pattern.compile(vPattern);
        Matcher vM = vR.matcher(msg);
        if(vM.matches() || msg.startsWith("附录")){
            return true;
        }
        return false;
    }

    public static boolean isTwoLevelTitle(String msg){
        // 获取
        String vPattern ="^\\d{1,2}\\.\\d{1,2}\\.\\d+.*$";
        Pattern vR = Pattern.compile(vPattern);
        Matcher vM = vR.matcher(msg);
        return vM.matches();
    }


    private static boolean isTitleLevel(String msg){

        String vPattern ="^\\d{1,2}\\.\\s{0,2}.*$";
        Pattern vR = Pattern.compile(vPattern);
        Matcher vM = vR.matcher(msg);
        return vM.matches();
    }
}
